<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>shellSort</title>
</head>
<body>
<script>
    function shellSort(arr) {
        var len = arr.length,
            temp,
            gap = 5;
        while ( gap > 0) {
            gap = Math.floor(gap/2);
            for (var i = gap; i < len; i++) {
                temp = arr[i];
                var j = i-gap;
                while ( j >= 0 && arr[j] > temp ) {
                    arr[j+gap] = arr[j];
                    j-=gap;
                }
                arr[j+gap] = temp;
            }
        }
        console.timeEnd('希尔排序耗时:');
        return arr;
    }
    var arr=[3,44,38,5,47,15,36,26,27,2,46,4,19,50,48];
    console.log(shellSort(arr));//[2, 3, 4, 5, 15, 19, 26, 27, 36, 38, 44, 46, 47, 48, 50]

</script>
</body>
</html>